package conf

import (
	"encoding/json"
	"io/ioutil"
	"os"
	"path/filepath"
)

type CacheCfg struct {
	CacheName   string   `json:"cache_name"`
	Capacity    int      `json:"capacity"`
	SelfAddr    string   `json:"self_addr"`
	ClusterAddr []string `json:"cluster_addr"`
}

func InitCfg() (cacheCfg *CacheCfg, err error) {
	var (
		content []byte
		path    string
	)
	path, _ = os.Getwd()
	path = filepath.Join(path, "conf", "conf.json")
	if content, err = ioutil.ReadFile(path); err != nil {
		return
	}
	if err = json.Unmarshal(content, &cacheCfg); err != nil {
		return
	}
	return
}
